package com.lkd.http.controller;

import com.lkd.entity.NodeEntity;
import com.lkd.entity.RegionEntity;
import com.lkd.entity.VendingMachineEntity;
import com.lkd.http.controller.vo.NodeReq;
import com.lkd.service.NodeService;
import com.lkd.vo.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/node")
public class NodeController {

    @Autowired
    private NodeService nodeService;

    /**
     * 分页搜索
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/search")
    Pager<NodeEntity> search(
            @RequestParam(value = "pageIndex",required = false,defaultValue = "1") Long pageIndex,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10") Long pageSize,
            @RequestParam(value = "name",required = false,defaultValue = "") String name,
            @RequestParam(value = "regionId",required = false,defaultValue = "") Long regionId
    ){

        return nodeService.search(pageIndex,pageSize,name,regionId);
    }

    /**
     * 查询详情
     * @return
     */
    @GetMapping("/vmList/{id}")
    List<VendingMachineEntity> vmListByNodeId(@PathVariable("id") Long nodeId){

        return nodeService.vmListByNodeId(nodeId);
    }
    /**
     * 新增
     * @return
     */
    @PostMapping()
    boolean addNode(@RequestBody NodeReq nodeReq){

        return nodeService.addNode(nodeReq);
    }

    /**
     * 修改
     * @return
     */
    @PutMapping("/{id}")
    boolean updateNode(@PathVariable("id") Long id ,  @RequestBody NodeReq nodeReq){

        return nodeService.updateNode(id,nodeReq);
    }
    /**
     * 删除
     * @return
     */
    @DeleteMapping("/{id}")
    boolean deleteNode(@PathVariable("id") Long id){
        // nodeService.removeById(id);
        return nodeService.deleteNode(id);
    }
}
